/**
 * 
 */
package com.aat.dxfy.thread.demo01;

/**
 * @date 2016年6月29日 下午2:41:20
 * @author 新歌<xingeking@163.com>
 * @email xingeking@163.com
 * @version v1.0
 * @function 功能是：
 * @info java spring
 * @update none
 */
public class Account2 {
	private String accountNum;
	private Integer money;

	public Account2(String accountNum, Integer money) {
		this.accountNum = accountNum;
		this.money = money;
	}

	public String getAccountNum() {
		return accountNum;
	}

	public void setAccountNum(String accountNum) {
		this.accountNum = accountNum;
	}

	public Integer getMoney() {
		return money;
	}

	public void setMoney(Integer money) {
		this.money = money;
	}

	public synchronized void quqian(Integer quqian){
		if(money>quqian){
			System.out.println(Thread.currentThread().getName()+" 从"+accountNum+"账户取钱成功!取出金额:"+quqian);
			
			 try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			 money = (money-quqian);
			System.out.println("\t"+accountNum+"账户余额为:"+money);
		}else{
			System.out.println(Thread.currentThread().getName()+" 从"+accountNum+"账户取钱失败!余额不足");
		}
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((accountNum == null) ? 0 : accountNum.hashCode());
		result = prime * result + ((money == null) ? 0 : money.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Account2 other = (Account2) obj;
		if (accountNum == null) {
			if (other.accountNum != null)
				return false;
		} else if (!accountNum.equals(other.accountNum))
			return false;
		if (money == null) {
			if (other.money != null)
				return false;
		} else if (!money.equals(other.money))
			return false;
		return true;
	}
	
	

}
